package com.springsummer.information.green.webmvc;


import java.util.LinkedHashMap;
import java.util.Map;

public class ModelAndView {


    private Model model;

    private String viewName;

    private View viewObject;

    public ModelAndView() {
        this.model = new NormalModelImpl();
    }

    public ModelAndView(String viewName) {
        this.viewName = viewName;
        this.model = new NormalModelImpl();
    }

    public String getViewName() {
        return viewName;
    }

    public void setViewName(String viewName) {
        this.viewName = viewName;
    }

    public View getViewObject() {
        return viewObject;
    }

    public void setViewObject(View viewObject) {
        this.viewObject = viewObject;
    }

    public ModelAndView addObject(String attributeName, Object attributeValue) {
        model.addAttribute(attributeName, attributeValue);
        return this;
    }

    public ModelAndView addAllObjects(Map<String, ?> modelMap) {
        model.addAllAttributes(modelMap);
        return this;
    }

    public Map<String,Object> getModelMap(){
        NormalModelImpl concurrentModel=(NormalModelImpl)model;
        Map<String,Object> modelMap=new LinkedHashMap<>();
        modelMap.putAll(concurrentModel);
        return modelMap;
    }

}
